import csv

data = {'id':'123','name':'anjing','age':'26'}
data2 = {'id':'123', 'sex':"man", 'name':'anjing','age':'26'}
# 加入参数“enwline=''”
with open('D:\\learn_and_test_data\\123.csv','a',newline='')as f:
    #fieldnames = {'id','name','age'}
    #writer = csv.DictWriter(f,fieldnames=list(data2.keys()))
    writer = csv.DictWriter(f, fieldnames=["id", "age", "name", "sex"])
    writer.writeheader()
    writer.writerow(data2)
f.close()
